-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Autocomplete.Combobox] Convert to functional component #2918
Conversation
👋 Thanks for opening your first pull request. A contributor should give feedback soon. If you haven’t already, please check out the contributing guidelines. |
🟢 This pull request modifies 3 files and might impact 1 other files. Details:All files potentially affected (total: 1)📄
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on @genevieveluyt!
I've not ran this just yet to test behaviour, but I've spotted some simplifications that could be done
(OptionDescriptor | ActionListItemDescriptor)[] | ||
>([]); | ||
const [popoverActive, setPopoverActive] = useState<boolean>(false); | ||
const [popoverWasActive, setPopoverWasActive] = useState<boolean>(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, though tbh I'm not very clear on why we need to track the previous value of the popover state
If we do indeed still need this then it seems like an idea case for a usePrevious utility hook. We don't currently depend upon that @shopify/react-hooks
and instead roll our own helpers, so copying that hook into our utilities folder at src/utilities/use-previous.ts
(and its test at `src/utilities/use-previous.test.ts) would be the right place to put it. That pattern matches our other utility hooks like useToggle.
usePrevious should save a bunch of setPopoverActive(false); setPopoverWasActive(false);
code, as we can only talk about setting popoverActive
, and not worry about popoverWasActive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the previous state and it didn't break any tests. I'm not sure if that logic was there for a specific case not covered by tests though 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more little tidyings that became apparent since the prior simplifications
Just gave this a click around in storybook and seems good to me. I'd appreciate some extra eyes though as I'm not that familiar with the Comobox's behaviour. @dfmcphee / @chloerice would you be able to take some time next week to give this a review too? |
Oh and a little expectation setting: This PR alone won't solve the automatic id mismatches between server and client, but the converting it to a functional component is a prerequisite of that future fix, which will be inside useUniqueId() - either through adding functionality ourselves or by leveraging useOpaqueIdentifier() |
Ah ok I misunderstood. That means I'll still need to set the ID manually for the time being? |
Hey @genevieveluyt, thanks for working on this! I'll tophat/review this by EOD Wednesday 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @genevieveluyt, 🎩 looks good 👍(any issues I found pre-exist these changes) Thank you for contributing ❤️!!!
You'll just need to add an entry to UNRELEASED.md
under Code quality
to pass the change log check
- Converted `ComboBox` to a functional component ([#2918](https://github.com/Shopify/polaris-react/pull/2918))
Co-Authored-By: Chloe Rice <[email protected]>
🎉 Thanks for your contribution to Polaris React! |
Thanks @genevieveluyt! |
WHY are these changes introduced?
The Autocomplete component causes the following warning if used with server-side rendering:
This is a known problem: #1761
Although this PR does not directly fix that problem, converting the Combobox to a functional component and having it use the
useUniqueId
hook is a prerequisite for fixing the automatic ID generation in the future.WHAT is this pull request doing?
Converts the Autocomplete Combobox component into a functional component and uses the
useUniqueId
hook.How to 🎩
Not easily testable without server side rendering 🤔
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist
README.md
with documentation changes